package com.yonyou.pmclouds.team.processor;

import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoUpdateProcessor;
import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.bp.template.SingleDeleteBpTemplate;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.team.entity.TeamEnterpriseVO;
import com.yonyou.pmclouds.team.entity.TeamMemberVO;
import com.yonyou.pmclouds.team.mapper.TeamMapper;

public class TeamEntDeleteCheck implements SingleProcessor<TeamEnterpriseVO> {
    private TeamMapper mapper;

    public TeamEntDeleteCheck(TeamMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void process(TeamEnterpriseVO vo, TeamEnterpriseVO orig) throws BusinessException {
        String ent = orig.getPkEnterprise();
        String project = orig.getPkProject();
        TeamMemberVO[] memberVOS = mapper.queryTeamByProjectAndEnts(project,new String[]{ent});
//        if (count > 0) {
//            throw new BusinessException("项目团队中依然有该企业用户，所以不能移除该企业！\n" +
//                    "请在项目团队中移除该企业用户后再试一下。");
//        }
        SingleDeleteBpTemplate<TeamMemberVO> bp = new SingleDeleteBpTemplate<TeamMemberVO>(mapper);
        bp.addBeforeProcessor(new AuditInfoUpdateProcessor<TeamMemberVO>());
        for (TeamMemberVO memberVO:
                memberVOS) {
            bp.delete(memberVO);
        }
    }

}
